package com.lepu.app.widget;

import java.util.ArrayList;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.app.utils.BitmapLoadUtil;
import com.app.utils.Utils;
import com.core.lib.application.BaseFragmentActivity;
import com.core.lib.core.AsyncRequest;
import com.core.lib.ui.auto_viewpager.AutoScrollViewPager;
import com.core.lib.utils.main.UtilityBase;
import com.core.lib.utils.photo.UniversalImageLoadTool;
import com.lepu.app.main.bean.BeanFocus;
import com.lepu.pasm.R;

public class FocusOneView extends LinearLayout implements AsyncRequest {

	public static final int TYPE_DEFAULT = 10;
	public static final int TYPE_STORE = 11;

	private ArrayList<BeanFocus> mFocusList;

	public AutoScrollViewPager mAutoScrollViewPager;

	private BaseFragmentActivity mBaseFragmentActivity = null;

	public FocusOneView(Context context, ArrayList<BeanFocus> dataList) {
		super(context);

		mFocusList = dataList;
		mBaseFragmentActivity = (BaseFragmentActivity) context;

		LayoutInflater.from(mBaseFragmentActivity).inflate(R.layout.main_focus_one_view_acticle, this, true);
		init();
	}

	public FocusOneView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	private void init() {

		FrameLayout contentLayout = (FrameLayout) findViewById(R.id.contentLayout);

		WindowManager wm = (WindowManager) mBaseFragmentActivity
				.getSystemService(Context.WINDOW_SERVICE);
		@SuppressWarnings("deprecation")
		int width = wm.getDefaultDisplay().getWidth();
		LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT,
				LayoutParams.WRAP_CONTENT);
		params.width = width;
		params.height = width * 8 / 25;// width * 9 / 16;
		contentLayout.setLayoutParams(params);
		
		final BeanFocus item = mFocusList.get(0);
		ImageView imageView = (ImageView) findViewById(R.id.autoScrollViewPager);
		imageView.setScaleType(ImageView.ScaleType.FIT_XY);
		//UniversalImageLoadTool.disPlayOrign(item.Cover, imageView,R.drawable.default_icon_banner);
		BitmapLoadUtil.displayImage(R.drawable.default_icon_banner, item.Cover, imageView);

		imageView.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View arg0) {

				int type = UtilityBase.parseInt(item.LinkTargetType);
				Utils.jumpFocusPushClick(mBaseFragmentActivity, false,
						type, item.ArticleID, item.LinkURL,
						item.LinkTargetID, item.ViewCount,
						item.FavourCount,item.Cover,item.ArticleDescription);
			}
		});

	}

	@Override
	public void RequestComplete(Object arg0, Object arg1) {
		
	}

	@Override
	public void RequestError(Object arg0, int arg1, String arg2) {
		
	}

}
